<?php

	// Variable Globale
	global $xview,$dbi,$go_user;
	// Consistency Check
	$fid = $xview->GetValue('fid');
	if(empty($fid)) $xview->SysError();
	// Get Data
	$s_files = $dbi->fetch_row("SELECT url,uploaded_on AS udate,userid FROM z_files WHERE fid = '$fid' ",'array');
	// Authority Check
	$idusr = $go_user->GetIdusr();
	$adele = false;
	if(permission_check("Files-Delete",$idusr))
		$adele = true;

	$delay = ( time() - $s_files['udate'] ) / 3600 ;
	if($adele || ( $idusr == $s_files['userid'] && $delay < 0.5 ) )
	{
	
		if(isset($_POST['fid']))
		{
			$fid = $_POST['fid'];
			unlink($s_files['url']);
			$sql  = "DELETE FROM z_files WHERE fid='$fid'";
			$dbi->query($sql);
			$update['fid'] = "";
			$dbi->update("events",$update,"WHERE fid='$fid'");
			echo GMsg('FILE',5);
		}
		else
		{
			// Text in case of deactivation
			$title = GMsg('FILE',3);
			$descr = GMsg('FILE',4);
			$iid = $xview->GetValue('issueid');
			$gid = $xview->GetValue('gid');
			if(!empty($iid))
				$baurl = "\'?module=issues&action=files&issueid=$iid\'";
			elseif(!empty($gid))
				$baurl = "\'?module=issues&action=gfiles&gid=$gid\'";
			else
				$baurl = null;
		
			$link1 = "fm_gen_save('?module=files&action=del','&fid=$fid',null,'Refresh($baurl);')";
			// Popup To confirm action
			$o_popup = new Popup2Conf('dbox',$title,$descr,$link1,null,null,null,400);
			echo $o_popup->Display();
		}
	}

?>


